import collections

class Player:
    '''
    Player that cooperates on the first round, then cooperates with AllC (unconditional hunters) and players cooperating with all but AllD (unconditional slackers). When only AllC players are cooperating (i.e., hunting), always defect (i.e., slack).
    
    This strategy views the first round as a chance to build reputation. Future
    correct responses to AllD will lower reputation, hurting the chances of
    cooperation with conditional cooperators. As a result, since we begin with
    no information on other players, provided there is a sufficient population
    of conditional cooperators it makes sense to cooperate in the first round.

    For the remainder of the game I wanted to reduce my chance of getting the
    sucker payoff. My chosen strategy was to detect AllC players and
    Almost-AllC players. I define Almost-AllC players as those who cooperate
    unless they are paired with AllD. In the second stage of the game
    I cooperate (i.e., hunt) with AllC and Almost-AllC and defect (i.e., slack)
    otherwise.  
    '''

    def __init__(self):
        pass # do nothing

    def hunt_choices(self, round_number, current_food, current_reputation, m, player_reputations):
        if round_number == 1:
            # cooperate (i.e. hunt) with everyone in the first round. This follows tit-for-tat and other typically winning prisoner's dilemma strategies
            return ['h']*len(player_reputations)
        else:
            # see if anyone besides AllC (unconditional hunters) are defecting
            # start by creating a counter
            count = collections.Counter(player_reputations)
            # if the number of AllC (count[1]) and the number of AllD (count[0]) is less than the number of players
            # i.e., if I am paired with other types as well
            if count[1] + count[0] < len(player_reputations):
                # then cooperate (i.e., hunt) with those who have a reputation that suggests they are Almost-AllC
                rep_thresh = 1.0 - (count[0] / len(player_reputations))
                return ['h' if rep>rep_thresh else 's' for rep in player_reputations]
            else:
                # otherwise defect (i.e., slack) for each decision
                return ['s']*len(player_reputations)

    def hunt_outcomes(self, food_earnings):
        pass # do nothing

    def round_end(self, award, m, number_hunters):
        pass # do nothing
